#include "widget.h"
#include "ui_widget.h"

#include <QMenu>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_toolBox_currentChanged(int index)
{
    ui->tabWidget->setCurrentIndex(index);
}

void Widget::on_toolButton_clicked()
{
    QListWidgetItem* item = new QListWidgetItem();
    item->setText("张三");
    item->setCheckState(Qt::Checked);
    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
    ui->listWidget->insertItem(0, item);
}

void Widget::on_toolButton_2_clicked()
{
    int row = ui->listWidget->currentRow();
    QListWidgetItem* item = ui->listWidget->takeItem(row);

    delete item;
}

void Widget::on_listWidget_customContextMenuRequested(const QPoint &pos)
{
     QMenu* menu = new QMenu(this);
     menu->addAction(ui->actionlist_ins);
     menu->addAction(ui->actionlist_del);
     menu->exec(QCursor::pos());

     delete menu;
}

void Widget::on_actionlist_ins_triggered()
{
    QListWidgetItem* item = new QListWidgetItem();
    item->setText("张三");
    ui->listWidget->insertItem(0, item);
}

void Widget::on_actionlist_del_triggered()
{
    on_toolButton_2_clicked();
}


void Widget::on_tabWidget_currentChanged(int index)
{
    ui->toolBox->setCurrentIndex(index);
}
